package com.kgc.onlineLife.service.impl;



import com.kgc.onlineLife.bean.Customer;
import com.kgc.onlineLife.mapper.CustomerMapper;
import com.kgc.onlineLife.service.CustomerService;
import com.kgc.onlineLife.util.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CustomerServiceImpl implements CustomerService {

    @Autowired
    private CustomerMapper customerMapper;

    /**
    * @author: HarryXzy
    * @date: 2022/4/14 8:30 下午
    * @return:
    * @description: 前台顾客登陆
    **/
    @Override
    public Customer foreLogin(Customer customer) {
        Customer cust=customerMapper.getCustomerByNameAndPwd(customer.getName(),customer.getPassword());
        if(cust!=null){
            return cust;
        }else{
            return null;
        }
    }

    /**
    * @author: HarryXzy
    * @date: 2022/4/14 9:24 下午
    * @return:
    * @description: 检查用户名是否重复
    **/
    @Override
    public Customer checkName(String name) {
        Customer cust=customerMapper.getCustomerByNameAndPwd(name,"");
        if(cust!=null){
            return cust;
        }else{
            System.out.println("用户名可用");
            return null;
        }
    }

    /**
    * @author: HarryXzy
    * @date: 2022/4/14 9:44 下午
    * @return:
    * @description: 保存customer
    **/
    @Override
    public void save(Customer customer) {
        customerMapper.insertCustomer(customer);
    }

    @Override
    public List<Customer> queryCustomers(Page page) {
        return customerMapper.selectCustomers(page);
    }

    @Override
    public List<Customer> queryCustomersByName(String name) {
        return customerMapper.selectCustomersByName(name);
    }

    @Override
    public boolean removeCustomerById(Integer id) {
        return customerMapper.deleteCustomerById(id) > 0;
    }

    @Override
    public Customer queryCustomerById(Integer id) {
        return customerMapper.selectCustomerById(id);
    }

    @Override
    public boolean modCustomerById(Customer customer) {
        return customerMapper.updateCustomerById(customer) > 0;
    }

    @Override
    public boolean changeCustomerStatus(Integer id) {
        return customerMapper.updateCustomerStatus(id, customerMapper.selectCustomerById(id).getStatus() == 0 ? 1 : 0 ) > 0;
    }
}
